package com.ruoyi.web.controller.fenxi;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RiskLevelData;
import com.ruoyi.system.service.IRiskLevelDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 风险等级Controller
 * 
 * @author ruoyi
 * @date 2022-10-01
 */
@Controller
@RequestMapping("/system/resikLevel")
public class RiskLevelDataController extends BaseController
{
    private String prefix = "system/resikLevel";

    @Autowired
    private IRiskLevelDataService riskLevelDataService;

    @RequiresPermissions("system:resikLevel:view")
    @GetMapping()
    public String resikLevel()
    {
        return prefix + "/resikLevel";
    }

    /**
     * 查询风险等级列表
     */
    @RequiresPermissions("system:resikLevel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RiskLevelData riskLevelData)
    {
        startPage();
        List<RiskLevelData> list = riskLevelDataService.selectRiskLevelDataList(riskLevelData);
        return getDataTable(list);
    }

    /**
     * 导出风险等级列表
     */
    @RequiresPermissions("system:resikLevel:export")
    @Log(title = "风险等级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RiskLevelData riskLevelData)
    {
        List<RiskLevelData> list = riskLevelDataService.selectRiskLevelDataList(riskLevelData);
        ExcelUtil<RiskLevelData> util = new ExcelUtil<RiskLevelData>(RiskLevelData.class);
        return util.exportExcel(list, "风险等级数据");
    }

    /**
     * 新增风险等级
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存风险等级
     */
    @RequiresPermissions("system:resikLevel:add")
    @Log(title = "风险等级", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RiskLevelData riskLevelData)
    {
        return toAjax(riskLevelDataService.insertRiskLevelData(riskLevelData));
    }

    /**
     * 修改风险等级
     */
    @RequiresPermissions("system:resikLevel:edit")
    @GetMapping("/edit/{ID}")
    public String edit(@PathVariable("ID") Integer ID, ModelMap mmap)
    {
        RiskLevelData riskLevelData = riskLevelDataService.selectRiskLevelDataByID(ID);
        mmap.put("riskLevelData", riskLevelData);
        return prefix + "/edit";
    }

    /**
     * 修改保存风险等级
     */
    @RequiresPermissions("system:resikLevel:edit")
    @Log(title = "风险等级", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RiskLevelData riskLevelData)
    {
        return toAjax(riskLevelDataService.updateRiskLevelData(riskLevelData));
    }

    /**
     * 删除风险等级
     */
    @RequiresPermissions("system:resikLevel:remove")
    @Log(title = "风险等级", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(riskLevelDataService.deleteRiskLevelDataByIDs(ids));
    }
}
